package com.ruoyi.wallet.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wallet.domain.DistributionWallet;
import com.ruoyi.wallet.service.IDistributionWalletService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销钱包Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/ruoyi/wallet")
public class DistributionWalletController extends BaseController
{
    @Autowired
    private IDistributionWalletService distributionWalletService;

    /**
     * 查询分销钱包列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:wallet:list')")
    @GetMapping("/list")
    public TableDataInfo list(DistributionWallet distributionWallet)
    {
        startPage();
        List<DistributionWallet> list = distributionWalletService.selectDistributionWalletList(distributionWallet);
        return getDataTable(list);
    }

    /**
     * 导出分销钱包列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:wallet:export')")
    @Log(title = "分销钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DistributionWallet distributionWallet)
    {
        List<DistributionWallet> list = distributionWalletService.selectDistributionWalletList(distributionWallet);
        ExcelUtil<DistributionWallet> util = new ExcelUtil<DistributionWallet>(DistributionWallet.class);
        util.exportExcel(response, list, "分销钱包数据");
    }

    /**
     * 获取分销钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:wallet:query')")
    @GetMapping(value = "/{walletId}")
    public AjaxResult getInfo(@PathVariable("walletId") Long walletId)
    {
        return success(distributionWalletService.selectDistributionWalletByWalletId(walletId));
    }

    /**
     * 新增分销钱包
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:wallet:add')")
    @Log(title = "分销钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DistributionWallet distributionWallet)
    {
        return toAjax(distributionWalletService.insertDistributionWallet(distributionWallet));
    }

    /**
     * 修改分销钱包
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:wallet:edit')")
    @Log(title = "分销钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DistributionWallet distributionWallet)
    {
        return toAjax(distributionWalletService.updateDistributionWallet(distributionWallet));
    }

    /**
     * 删除分销钱包
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:wallet:remove')")
    @Log(title = "分销钱包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{walletIds}")
    public AjaxResult remove(@PathVariable Long[] walletIds)
    {
        return toAjax(distributionWalletService.deleteDistributionWalletByWalletIds(walletIds));
    }
}
